/*
 * Copyright (c) Meta Platforms, Inc. and affiliates.
 *
 * This source code is dual-licensed under either the MIT license found in the
 * LICENSE-MIT file in the root directory of this source tree or the Apache
 * License, Version 2.0 found in the LICENSE-APACHE file in the root directory
 * of this source tree. You may select, at your option, one of the
 * above-listed licenses.
 */

#![deny(warnings, clippy::all, rustdoc::broken_intra_doc_links)]
// See https://github.com/rust-lang/rust/pull/60562
// #![deny(missing_docs)]

//! This crate offers a workaround for [issue](https://github.com/rust-lang/rfcs/issues/752).
//! The gist of it is that `include!` proc macro will include the content of
//! lib.rs file stored inside OUT_DIR, presumably generated by cargo's build
//! script.
//!
//! # Example
//!
//! ```
//! ::codegen_includer_proc_macro::include!();
//! hello_world(); // This was included from $OUT_DIR/lib.rs
//! ```

extern crate proc_macro;
use std::env;
use std::path::Path;

use proc_macro::TokenStream;
use quote::quote;

/// See crate's documentation
#[proc_macro]
pub fn include(_: TokenStream) -> TokenStream {
    let path_to_include = Path::new(&env::var("OUT_DIR").unwrap())
        .join("lib.rs")
        .to_str()
        .unwrap()
        .to_string();

    let result = quote! {
        #[path = #path_to_include]
        #[allow(unused_attributes)]
        mod codegen_included;
        pub use codegen_included::*;
    };
    result.into()
}
